home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / System Extras Headers / GX Printing Libraries / CollectionLibrary.c next >
Encoding:
C/C++ Source or Header  |  1994-08-17  |  7.4 KB  |  279 lines  |  [TEXT/MMCC]

  1. /* ------------------------------------------------------------------------------
  2.  
  3.     FILENAME
  4.         CollectionLibrary.c
  5.         
  6.     DESCRIPTION
  7.         Handy printing collection functions.
  8.         
  9.     COPYRIGHT
  10.          © Apple Computer, Inc. 1990-1991
  11.          All rights reserved. 
  12.     
  13. -------------------------------------------------------------------------------- */
  14.  
  15. #include <PrintingManager.h>
  16. #include <PrintingLibraries.h>
  17. #include <Errors.h>
  18.  
  19.  
  20. #define kCategoryMask 0x0000FFFF
  21.  
  22.  
  23.  
  24. /****************************************************************************************
  25.  
  26.                             SetCollectionItemCategory
  27.                             
  28.     function :
  29.                     Assigns a tag/ID pair to a category in the given collection.
  30.     parameters :
  31.                     the collection, the tag, the ID, and the category
  32.  
  33. ****************************************************************************************/
  34. OSErr SetCollectionItemCategory (    Collection theCollection,
  35.                                     CollectionTag tag,
  36.                                     long tagID,
  37.                                     gxCollectionCategory theCategory)
  38. {
  39.     OSErr     anErr;
  40.  
  41.     
  42. // Set the item's attributes to be the provided category, ORed with the existing bits.
  43.  
  44.     anErr = SetCollectionItemInfo(    theCollection,
  45.                                     tag,
  46.                                     tagID,
  47.                                     kCategoryMask,
  48.                                     (long) theCategory);
  49.                                     
  50.     return (anErr);
  51. }
  52. /****************************************************************************************
  53.  
  54.                             GetCollectionItemCategory
  55.                             
  56.     function :
  57.                     Returns the category assigned to the tag/ID pair 
  58.                     in the given collection.
  59.     parameters :
  60.                 
  61. ****************************************************************************************/
  62. OSErr GetCollectionItemCategory( Collection         theCollection,
  63.                                    CollectionTag         tag,
  64.                                  long                tagID,
  65.                                  gxCollectionCategory *theCategory)
  66. {
  67.     OSErr     anErr;
  68.     long    attributes;
  69.     
  70.     
  71. // Get the item's attributes in the provided category. Then get the category bits
  72.  
  73.     anErr = GetCollectionItemInfo(    theCollection,
  74.                                     tag,
  75.                                     tagID,
  76.                                     dontWantIndex,
  77.                                     dontWantSize,
  78.                                     &attributes);
  79.                                     
  80.     *theCategory = attributes & kCategoryMask;
  81.     
  82.     return (anErr);
  83. }
  84.  
  85.  
  86. /****************************************************************************************
  87.  
  88.                             RemoveCollectionCategory
  89.                             
  90.     function :
  91.                     Removes a category from the given collection
  92.     parameters :
  93.                 
  94. ****************************************************************************************/
  95. OSErr RemoveCollectionCategory( Collection             theCollection,
  96.                                   gxCollectionCategory    theCategory)
  97. {
  98.  
  99. // Yank all the items which have those bits set.
  100.  
  101.     PurgeCollection(theCollection, theCategory, theCategory);
  102.  
  103.     return (noErr);
  104. }
  105.  
  106. /****************************************************************************************
  107.  
  108.                             GetCollectionItemLock
  109.                             
  110.     function :
  111.                     Returns true if the item is locked
  112.     parameters :
  113.                     the collection, tag, and ID
  114.                     
  115.     returns:        
  116.                     OSErrs
  117.                     *isLocked contains the lock state
  118.                 
  119. ****************************************************************************************/
  120. OSErr GetCollectionItemLock( Collection     theCollection,
  121.                              CollectionTag     tag,
  122.                              long            tagID,
  123.                              Boolean        *isLocked)
  124. {
  125.     OSErr     anErr;
  126.     long    attributes;
  127.     
  128. // Get the attributes of the item in question
  129.  
  130.     anErr = GetCollectionItemInfo(    theCollection,
  131.                                     tag,
  132.                                     tagID,
  133.                                     nil,            // don't want the index
  134.                                     nil,            // don't want the size
  135.                                     &attributes);
  136.  
  137.  
  138. // Then determine if "locked" is one of the attributes.
  139.  
  140.     *isLocked = ((attributes & collectionLockMask) == collectionLockMask);
  141.  
  142.     return (anErr);
  143. }
  144. /****************************************************************************************
  145.  
  146.                             SetCollectionItemLock
  147.                             
  148.     function :
  149.                     Locks the given item
  150.     parameters :
  151.                 
  152. ****************************************************************************************/
  153. OSErr SetCollectionItemLock( Collection     theCollection,
  154.                              CollectionTag     tag,
  155.                              long            tagID,
  156.                              Boolean        lockIt)
  157. {
  158.     OSErr     anErr;
  159.     long    lockState;
  160.     
  161.     
  162. // Set the bit according to lockIt.
  163.  
  164.     if (lockIt)
  165.         lockState = collectionLockMask;
  166.     else
  167.         lockState = 0;
  168.         
  169.     anErr = SetCollectionItemInfo(    theCollection,
  170.                                     tag,
  171.                                     tagID,
  172.                                     collectionLockMask,
  173.                                     lockState);
  174.  
  175.     return (anErr);
  176. }
  177.  
  178.  
  179. /****************************************************************************************
  180.  
  181.                             AddJobItem
  182.                             
  183.     function :
  184.                     Adds an item to a job collection.
  185.     parameters :
  186.                     the collection, the tag, the ID, and the category
  187.  
  188. ****************************************************************************************/
  189. OSErr AddJobItem (gxJob aJob, CollectionTag tag, long id, long itemSize, void *itemData)
  190. {
  191.     if (!aJob) return paramErr;
  192.     return AddCollectionItem(GXGetJobCollection(aJob), tag, id, itemSize, itemData);
  193. }
  194.  
  195.  
  196. /****************************************************************************************
  197.  
  198.                             AddFormatItem
  199.                             
  200.     function :
  201.                     Adds an item to a format collection.
  202.     parameters :
  203.                     the collection, the tag, the ID, and the category
  204.  
  205. ****************************************************************************************/
  206. OSErr AddFormatItem (gxFormat aFormat, CollectionTag tag, long id, long itemSize, void *itemData)
  207. {
  208.     if (!aFormat) return paramErr;
  209.     return AddCollectionItem(GXGetFormatCollection(aFormat), tag, id, itemSize, itemData);
  210. }
  211.  
  212.  
  213.  
  214. /****************************************************************************************
  215.  
  216.                             AddVolatileJobItem
  217.                             
  218.     function :
  219.                     Adds a purgeable item to a job collection.
  220.                     When called by driver, will auotmatically
  221.                     set the correct bits to make the item purgeable for that driver.
  222.     parameters :
  223.                     the collection, the tag, the ID, and the category
  224.  
  225. ****************************************************************************************/
  226. OSErr AddVolatileJobItem (gxJob aJob, CollectionTag tag, long id, long itemSize, void *itemData)
  227. {
  228.     OSErr anErr;
  229.     Collection jobCollection;
  230.     
  231.     if (!aJob) return paramErr;
  232.     jobCollection = GXGetJobCollection(aJob);
  233.     
  234.     anErr = AddCollectionItem(jobCollection, tag, id, itemSize, itemData);
  235.     
  236.     if (!anErr) {
  237.         gxCollectionCategory category = (GXGetJobPrinter(aJob) == GXGetJobOutputPrinter(aJob))
  238.                                     ? gxVolatileOutputDriverCategory
  239.                                     : gxVolatileFormattingDriverCategory;
  240.                                     
  241.         (void) SetCollectionItemCategory(jobCollection, tag, id, category);
  242.     }
  243.     return anErr;
  244. }
  245.  
  246.  
  247. /****************************************************************************************
  248.  
  249.                             AddVolatileFormatItem
  250.                             
  251.     function :
  252.                     Adds a purgeable item to a format collection.
  253.                     When called by driver, will auotmatically
  254.                     set the correct bits to make the item purgeable for that driver.
  255.     parameters :
  256.                     the collection, the tag, the ID, and the category
  257.  
  258. ****************************************************************************************/
  259. OSErr AddVolatileFormatItem (gxFormat aFormat, CollectionTag tag, long id, long itemSize, void *itemData)
  260. {
  261.     OSErr anErr;
  262.     Collection formatCollection;
  263.     
  264.     if (!aFormat) return paramErr;
  265.     formatCollection = GXGetFormatCollection(aFormat);
  266.     
  267.     anErr = AddCollectionItem(formatCollection, tag, id, itemSize, itemData);
  268.     
  269.     if (!anErr) {
  270.         gxJob aJob = GXGetFormatJob(aFormat);
  271.         gxCollectionCategory category = (GXGetJobPrinter(aJob) == GXGetJobOutputPrinter(aJob))
  272.                                     ? gxVolatileOutputDriverCategory
  273.                                     :gxVolatileFormattingDriverCategory;
  274.                                     
  275.         (void) SetCollectionItemCategory(formatCollection, tag, id, category);
  276.     }
  277.     return anErr;
  278. }
  279.